﻿package com.shootingGame.renderableClasses
{
	import com.shootingGame.GamePlayManager;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.utils.getDefinitionByName;

	public class PickupObject extends GameObject
	{
		public static const ROTATION_SPEED : Number = 0.2;
		public var type : String;
		public function PickupObject(model:MovieClip, type:String)
		{
			super(model);
			isToBeRendered = true;
			isToBeUpdated = true;
			isInvulnerable = true;
			this.type = type;
			isViewAreaRenderOnly = true;
		}
		
		override public function update():void{
			super.update();
			facing += ROTATION_SPEED;
		}
		
		public function pickedUp() : GameObject{
			GamePlayManager.instance.pickupHolder.removeChild(this);
			var classRef : Class = flash.utils.getDefinitionByName(type) as Class;
			return new classRef();
		}
		
		override public function addObject_ToUpdateList():void
		{
			if(GamePlayManager.instance.pickupList.indexOf(this) == -1)
				GamePlayManager.instance.pickupList.push(this);
		}
		
		override public function removeObject_FromUpdateList():void
		{
			var pickupList : Array = GamePlayManager.instance.pickupList;
			pickupList.splice(pickupList.indexOf(this),1);
		}
		
	}
}